/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package app;

import java.io.*;

public class Statistics {
    private static final String lineSeparator = System.getProperty("line.separator");
    private static final String path = System.getProperty("user.dir") + "\\stats.txt";
    private static final Statistics stats = loadStatistics();
    
    
    private Statistics() { }
    
    public Statistics getStatistics() {
        return stats;
    }
    
    
    private static Statistics loadStatistics() {
        Statistics result = null;
        BufferedReader reader = null;
        
        try {
            reader = new BufferedReader(new FileReader(path));
            result = new Statistics();
            
            // wczytywanie danych
        }
        catch (Exception e) {
            System.err.println("Błąd podczas wczytywania statystyk.");
            result = new Statistics();
        }
        finally {
            if (reader != null) {
                try {
                    reader.close();
                }
                catch (Exception e) {
                    System.err.println("Błąd podczas kończenia wczytywania statystyk.");
                }
            }
        }
        
        return result;
    }
    
    public void Save() {
        BufferedWriter writer = null;
        
        try {
            writer = new BufferedWriter(new FileWriter(path, false));
            
            // zapis danych
        }
        catch (Exception e) {
            System.err.println("Błąd podczas zapisywania statystyk.");
        }
        finally {
            if (writer != null) {
                try {
                    writer.close();
                }
                catch (Exception e) {
                    System.err.println("Błąd podczas kończenia zapisywania statystyk.");
                }
            }
        }
    }
}
